/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package RMS;

import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.Vector;
import javax.microedition.rms.InvalidRecordIDException;
import javax.microedition.rms.RecordEnumeration;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
import javax.microedition.rms.RecordStoreNotFoundException;
import javax.microedition.rms.RecordStoreNotOpenException;

/**
 *
 * @author SamSung
 */
public class LoadImageInfoFromRecord {

    private static RecordStore rs;
    private static String vresultSign, vresultText, vsuggest, vmean;
    private static String[] vanswer;
    private static final String RECORD_NAME = "ImageInfo";


    public static int getRecordCount() {
        RecordEnumeration re = null;
        try {
            rs = RecordStore.openRecordStore(RECORD_NAME, true);
        } catch (RecordStoreException ex) {
            ex.printStackTrace();
        }
        int n;
        try {
            re = rs.enumerateRecords(null, null, false);
        } catch (RecordStoreNotOpenException ex) {
            ex.printStackTrace();
        }
        n = re.numRecords();
        try {
            rs.closeRecordStore();
        } catch (RecordStoreNotOpenException ex) {
            ex.printStackTrace();
        } catch (RecordStoreException ex) {
            ex.printStackTrace();
        }
        return n;
    }

    public static void loadRecord(int i) {
        try {
            rs = RecordStore.openRecordStore(RECORD_NAME, true);
        } catch (RecordStoreException ex) {
            ex.printStackTrace();
        }
        try {
            vanswer = new String[4];
            byte[] dt = rs.getRecord(i);
//                byte[] dt = new byte[rs.getRecordSize(recordId)];
            DataInputStream dis = new DataInputStream(new ByteArrayInputStream(dt));
            try {
                vresultSign = dis.readUTF();
                System.out.println(vresultSign);
                vresultText = dis.readUTF();
                System.out.println(vresultText);
                vsuggest = dis.readUTF();
                vmean = dis.readUTF();

                vanswer[0] = dis.readUTF();
                vanswer[1] = dis.readUTF();
                vanswer[2] = dis.readUTF();
                vanswer[3] = dis.readUTF();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        } catch (InvalidRecordIDException ex) {
            ex.printStackTrace();
        } catch (RecordStoreNotOpenException ex) {
            ex.printStackTrace();
        } catch (RecordStoreException ex) {
            ex.printStackTrace();
        }

        try {
            rs.closeRecordStore();
        } catch (RecordStoreNotOpenException ex) {
            ex.printStackTrace();
        } catch (RecordStoreException ex) {
            ex.printStackTrace();
        }
    }

    public static String[] getVanswer() {
        return vanswer;
    }

    public static String getVmean() {
        return vmean;
    }

    public static String getVresultSign() {
        return vresultSign;
    }

    public static String getVresultText() {
        return vresultText;
    }

    public static String getVsuggest() {
        return vsuggest;
    }
}
